﻿<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>权限管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 权限管理 </nav>
<div class="page-container">
	<div class="text-c">
			<input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="mName" name="">
			<input type="text" class="input-text" style="width:250px" placeholder="权限Url" id="mUrl" name="">
			<input type="text" class="input-text" style="width:250px" placeholder="权限代码" id="mCode" name="">
			<button type="button" class="btn btn-success" id="searchMenu" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
			<button type="button" class="btn btn-success" id="clearContion" name=""><i class="Hui-iconfont">&#xe665;</i>刷新页面</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="admin_permission_add('添加权限','${pageContext.request.contextPath}/common/menu/add.htm','','410')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加权限节点</a>
			</span> <span id="tolCount" class="r"></span> </div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">ID</th>
				<th width="200">权限名称(name)</th>
				<th>URL地址</th>
				<th>菜单编号(code)</th>
				<th>菜单父编号(pcode)</th>
				<th>菜单层级(levels)</th>
				<th>创建时间(createTime)</th>
				<th>修改时间(updateTime)</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody id="tbody">
		</tbody>
	</table>
	<%@ include file="../common/paging.jsp" %> 
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/my_js/page/page.js"></script>
<script type="text/javascript">

var data;
var name = "";
var code = "";
var url = "";
var maxResult = 10;

function admin_permission_add(title,url,w,h){
	layer_show(title,url);
}
/*管理员-权限-编辑*/
function menu_edit(title,url){
	layer_show(title,url,'','');
}

/*管理员-权限-删除*/
function menu_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			contentType: "application/json;charset=UTF-8",
			url: '${pageContext.request.contextPath}/common/Menu/'+id+'/deleteById.action',
			dataType: 'json',
			success: function(data){
				if(data.code == "200"){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				}else{
					layer.msg('删除失败!',{icon:2,time:1000});
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/* 查询全部数据   生成列表*/
function selectByPage(){
	 data = {"name":name,"code":code,"url":url,"firstResult":firstResult,"maxResult":maxResult};
	$.ajax({
		type:'post',
		url:'${pageContext.request.contextPath}/menu/queryPage.action',
		dataType:'json',
		contentType: "application/json;charset=UTF-8",
		data:JSON.stringify(data),
		success:function(data){
			if(data.code == "200"){
				DisplayListItems(data.data);
				tolCount = data.count;
				tolPage = parseInt(tolCount/maxResult)+ ((tolCount-parseInt(tolCount/maxResult))>0?1:0);
				$('#tolPage').val("共"+tolPage+"页");
				$('#thisPage').val("第"+(parseInt(firstResult/maxResult)+1)+"页");
				$('#tolCount').html("共有数据：<strong>"+tolCount+"</strong> 条");
			}else{
				layer.msg('系统错误!',{icon:2,time:1000});
			}
		},
		error:function(data){
			console.log(data.msg);
		},
	});
};


$('#searchMenu').click(function(){
	 name = $("#mName").val();
	 code = $("#mCode").val();
	 url = $("#mUrl").val();
	 firstResult = 1;
	 selectByPage();
	
});

$('#clearContion').click(function(){
	flush();
});

function flush(){
	
	$("#mName").val("")
	$("#mCode").val("")
	$("#mUrl").val("")
	name = $("#mName").val();
	code = $("#mCode").val();
	url = $("#mUrl").val();
	firstResult = 1;
	selectByPage();
}



//时间转换
function timestampToTime(timestamp) {
	   var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	   Y = date.getFullYear() + '-';
	   M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
	   D = date.getDate() + ' ';
	   h = date.getHours() + ':';
	   m = date.getMinutes() + ':';
	   s = date.getSeconds();
	   return Y+M+D +h+m+s;
}

/*菜单列表拼接 */
function DisplayListItems(list) {  
	
	var itemHTML;
	
    $.each(list, function(index, element) {  
         itemHTML += "<tr class='text-c'>"
		+"<td><input type='checkbox'></td>"
		+"<td >"+element.id+"</td>"
		+"<td >"+element.name+"</td>"
		+"<td >"+element.url+"</td>"
		+"<td >"+element.code+"</td>"
		+"<td >"+element.pcode+"</td>"
		+"<td >"+element.levels+"</td>"
		+"<td >"+timestampToTime(element.createTime)+"</td>"
		+"<td >"+timestampToTime(element.updateTime)+"</td>"
		+"<td class='f-14'><a title='编辑' href='javascript:;'"
		+"onclick='menu_edit(`菜单编辑`,`${pageContext.request.contextPath}/common/Menu/"+element.id+"/update.htm`)'"
		+"style='text-decoration:none'><i class='Hui-iconfont'>&#xe6df;</i></a> "
		+"<a title='删除' href='javascript:;' onclick='menu_del(this,"+element.id+")' class='ml-5' style='text-decoration:none'><i class='Hui-iconfont'>&#xe6e2;</i></a></td>"
		+"</tr>";  
    })
        $("#tbody").html(itemHTML);
}  

</script>
</body>
</html>